package HuaweiOD;

import java.util.Scanner;

public class 报数问题 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println(solve(in.nextInt()));
    }

    public static int solve(int n) {

        CycleLinkedList list = new CycleLinkedList();
        for (int i = 1; i <= n; i++) {
            list.append(i);
        }

        int num = 1;
        Node cur = list.head;
        while (list.size > 0) {
            if (num == 3) {
                num = 1;
                cur = list.remove(cur);
            } else {
                num++;
                cur = cur.next;
            }
        }

        return cur.val;
    }
}

class Node {
    int val;
    Node prev;
    Node next;

    public Node(int val) {
        this.val = val;
        this.prev = null;
        this.next = null;
    }
}

class CycleLinkedList {
    Node head;
    Node tail;
    int size;

    public CycleLinkedList() {
        this.head = null;
        this.tail = null;
        this.size = 0;
    }

    public void append(int val) {
        Node node = new Node(val);
        if (size > 0) {
            this.tail.next = node;
            node.prev = this.tail;
        } else {
            this.head = node;
        }

        this.tail = node;
        this.head.prev = this.tail;
        this.tail.next = this.head;
        this.size++;
    }

    public Node remove(Node cur) {
        Node prev = cur.prev;
        Node next = cur.next;

        prev.next = next;
        next.prev = prev;

        if (this.head == cur) {
            this.head = next;
        }
        if (this.tail == cur) {
            this.tail = prev;
        }

        this.size--;

        return next;
    }

}
